package com.cjgl.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cjgl.common.BaseResponse;
import com.cjgl.common.ResultUtils;
import com.cjgl.model.dto.score.SelectScoresByTermOrCourseNameREquest;
import com.cjgl.model.entity.TblScores;
import com.cjgl.service.TblScoresService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhangyuwu
 */
@RestController
@RequestMapping("/adminManagescoreInfo")
public class AdminManageScoreInfo {
	@Resource
	TblScoresService scoresService;

	/**
	 * 获取全部分数信息
	 *
	 * @param scoresRequest
	 * @param request
	 * @return
	 */
	@GetMapping
	public BaseResponse<Object> getAllScoresInfo(SelectScoresByTermOrCourseNameREquest scoresRequest, HttpServletRequest request) {

		String studentNo = scoresRequest.getStudentNo() == null ? "" : scoresRequest.getStudentNo();
		String courseNo = scoresRequest.getCourseNo() == null ? "" : scoresRequest.getCourseNo();

		Float heghtScoreSelect = scoresRequest.getHeghtScoreSelect() == null ? 100F : scoresRequest.getHeghtScoreSelect();
		Float lowScoreSelect = scoresRequest.getLowScoreSelect() == null ? 0F : scoresRequest.getLowScoreSelect();

		LambdaQueryWrapper<TblScores> scoreQueryWrapper = new LambdaQueryWrapper<>();
		scoreQueryWrapper
				.like(!StringUtils.isEmpty(studentNo), TblScores::getStudentNo, studentNo)
				.like(!StringUtils.isEmpty(courseNo), TblScores::getCourseNo, courseNo)
				.between(TblScores::getScore, lowScoreSelect, heghtScoreSelect);

		List<TblScores> tblScores = scoresService.getBaseMapper().selectList(scoreQueryWrapper);
		return ResultUtils.success(tblScores);
	}

}
